<script setup>
import { ref, onMounted } from 'vue';
import moment from 'moment';
// 咨询数据
const consultData = ref([]);

// 咨询接口
const infos = () => {
  uni.request({
    method: 'GET',
    url: 'http://10.31.71.52:7002/api/v1/infos',
    data: {
      currentPage: '1',
      pageSize: '4'
    },
    success: (res) => {
      res.data.data.forEach((t, k) => {
        let formattedDate = moment(Number(t.update_time)).format('YYYY-MM-DD HH:mm:ss');
        consultData.value.push({
          id: t.id,
          title: t.title + ',大家快来抢购！' + t.title + '快来抢购！',
          update_time: formattedDate,
          img: `http://10.31.71.52:7002/public/static/Homeimg/${k + 2}.png`
        })
      });
    }
  })
}
onMounted(() => {
  infos();
})
// 跳转详情
// consult_Details/consult_Details
const details = (id) => {
  uni.navigateTo({
    url:'/subpkg/consult_Details/consult_Details?id='+id,
  })
}

</script>

<template>
  <view class="box">
    <view class="item" v-for="(item, index) in consultData" :key="index" @click="details(item.id)">
      <view class="left">
        <image style="width: 100%;border-radius: 10px ;" :src="item.img" mode="widthFix" />
      </view>
      <view class="right">
        <view style="font-weight: bold;">{{ item.title }}</view>
        <view style="margin-top: 20%;">{{ item.update_time }}</view>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.box {
  width: 100vw;
  height: 100vh;
  padding: 20px;
  box-sizing: border-box;
  font-size: 14px;

  .item {
    width: 100%;
    display: flex;
    margin: 10px 0;

  }

  .left {
    width: 80%;
  }

  .right {
    padding: 10px;
  }
}
</style>
